﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Yoozoo.Gameplay.Liberty.Nodes;
using Yoozoo.Gta.Common;

public class TakeMoneyTransitionBehaviour : StateMachineBehaviour
{
    static int openBagAnimationHash = Animator.StringToHash("a_hum_frank_idle_to_openbag");
    static int closeBagAnimationHash = Animator.StringToHash("a_hum_frank_idle_to_closebag");
    private bool isInOpenBagStatus = false;

    // OnStateEnter is called before OnStateEnter is called on any state inside this state machine
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {

    }

    // OnStateUpdate is called before OnStateUpdate is called on any state inside this state machine
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if(!isInOpenBagStatus && openBagAnimationHash == stateInfo.shortNameHash)
        {
            if(stateInfo.normalizedTime - 1.0f > 1e-6)
            {
                isInOpenBagStatus = true;
                ResidentHandler.Inst.GetFunction("CityLuaFunction.OnEnterTakeMoneyState").Call();
            }
        }
    }

    // OnStateExit is called before OnStateExit is called on any state inside this state machine
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if(stateInfo.shortNameHash == closeBagAnimationHash)
        {
            isInOpenBagStatus = false;
        }

        if (StartTakeMoney.takeMoneyAnimSet != null && StartTakeMoney.takeMoneyAnimSet.TryGetValue(stateInfo.shortNameHash,out int stage))
        {
            StartTakeMoney.playerAnimEvent?.TriggerMoneyInBag(1);
        }
    }

    // OnStateMove is called before OnStateMove is called on any state inside this state machine
    //override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //    
    //}

    // OnStateIK is called before OnStateIK is called on any state inside this state machine
    //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //    
    //}

    // OnStateMachineEnter is called when entering a state machine via its Entry Node
    override public void OnStateMachineEnter(Animator animator, int stateMachinePathHash)
    {
 
    }

    // OnStateMachineExit is called when exiting a state machine via its Exit Node
    //override public void OnStateMachineExit(Animator animator, int stateMachinePathHash)
    //{
    //    
    //}
}
